#include "cpu/exec/template-start.h"

#define instr not

static void do_execute() {
	// DATA_TYPE result = ~op_src->val;
	// 提取src的值
	switch (op_src->type) {
		case OP_TYPE_REG:
			switch (op_src->reg) {
				case 0: op_src->val = cpu.eax; break;
				case 1: op_src->val = cpu.ecx; break;
				case 2: op_src->val = cpu.edx; break;
				case 3: op_src->val = cpu.ebx; break;
				case 4: op_src->val = cpu.esp; break;
				case 5: op_src->val = cpu.ebp; break;
				case 6: op_src->val = cpu.esi; break;
				case 7: op_src->val = cpu.edi; break;
				default: Assert(0, "op_src->reg = %d", op_src->reg);
			}
			break;
		case OP_TYPE_MEM:
			op_src->val = swaddr_read(op_src->addr, DATA_BYTE);
			break;
		case OP_TYPE_IMM:
			break;
	}
	// 手动进行非运算
	// OPERAND_W(op_src, result);
	DATA_TYPE result = ~op_src->val;
	// 赋值
	switch (op_src->type) {
		case OP_TYPE_REG:
			switch (op_src->reg) {
				case 0: cpu.eax = result; break;
				case 1: cpu.ecx = result; break;
				case 2: cpu.edx = result; break;
				case 3: cpu.ebx = result; break;
				case 4: cpu.esp = result; break;
				case 5: cpu.ebp = result; break;
				case 6: cpu.esi = result; break;
				case 7: cpu.edi = result; break;
				default: Assert(0, "op_src->reg = %d", op_src->reg);
			}
			break;
		case OP_TYPE_MEM:
			swaddr_write(op_src->addr, DATA_BYTE, result);
			break;
		default: Assert(0, "op_src->type = %d", op_src->type);
	}
	
	print_asm_template1();
}

make_instr_helper(rm)

#include "cpu/exec/template-end.h"
